﻿using System;
using System.Collections.Generic;
using System.Text;

namespace E.DAL
{
    public class DALUtils
    {

        #region Utils

        public static string GetInCondition(string parmName, string[] parms)
        {
            if (parms.Length > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(parmName);
                sb.Append(" IN (");
                foreach (string parm in parms)
                {
                    sb.Append(parm);
                    sb.Append(",");
                }
                string rst = sb.ToString();
                rst = rst.Substring(0, rst.Length - 1) + ") ";
                return rst;
            }
            else
                return "";
        }

        public static string GetInCondition(string parmName, IList<int> parms)
        {
            if (parms.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(parmName);
                sb.Append(" IN (");

                foreach (int parm in parms)
                {
                    sb.Append(parm);
                    sb.Append(",");
                }
                string rst = sb.ToString();
                rst = rst.Substring(0, rst.Length - 1) + ") ";
                return rst;
            }
            else
                return "";
        }

        public static string Convert2String(IList<int> parms)
        {
            if (parms.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                foreach (int parm in parms)
                {
                    sb.Append(parm);
                    sb.Append(",");
                }
                string rst = sb.ToString();
                rst = rst.Substring(0, rst.Length - 1);
                return rst;
            }
            else
                return "";
        }

        #endregion
    }
}
